<script>
	/* const myPlugin = requirePlugin('WechatSI'); */
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import {
		mapMutations
	} from 'vuex';
	export default {
		methods: {
			...mapMutations(['login']),
			getSetting(){
				let tmplIds="nhl6nxAHMVyDNW28DXe6WC4CX_x7QRpzWh3sSPDrk7M"
				// 这里是获取下发权限地方，根据官方文档，可以根据  wx.getSetting() 的 withSubscriptions   这个参数获取用户是否打开订阅消息总开关。后面我们需要获取用户是否同意总是同意消息推送。所以这里要给它设置为true 。
				wx.getSetting({
				      withSubscriptions: true,   //  这里设置为true,下面才会返回mainSwitch  
				      success: function(res){   
				      
				        // 调起授权界面弹窗 
				        if (res.subscriptionsSetting.mainSwitch) {  // 用户打开了订阅消息总开关
				          if (res.subscriptionsSetting.itemSettings != null) {   // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
				            let moIdState = res.subscriptionsSetting.itemSettings[tmplIds];  // 用户同意的消息模板id
				            if(moIdState === 'accept'){   
				              console.log('接受了消息推送');
				
				            }else if(moIdState === 'reject'){
				              console.log("拒绝消息推送");
				
				            }else if(moIdState === 'ban'){
				              console.log("已被后台封禁");
				
				            }
				          }else {
				              // 当用户没有点击 ’总是保持以上选择，不再询问‘  按钮。那每次执到这都会拉起授权弹窗
				            wx.showModal({
				              title: '提示',
				              content:'请授权开通服务通知',
				              showCancel: true,
				              success: function (ress) {
				                if (ress.confirm) {  
				                  wx.requestSubscribeMessage({   // 调起消息订阅界面
				                    tmplIds: [tmplIds],
				                    success (res) { 
				                      console.log('订阅消息 成功 ');
				                      console.log(res);
				                    },
				                    fail (er){
				                      console.log("订阅消息 失败 ");
				                      console.log(er);
				                    }
				                  })     
				                        
				                }
				              }
				            })
				          }
				
				        }else {
				          console.log('订阅消息未开启')
						  wx.showModal({
						    title: '提示',
						    content:'请授权开通服务通知',
						    showCancel: true,
						    success: function (ress) {
						      if (ress.confirm) {  
						        wx.requestSubscribeMessage({   // 调起消息订阅界面
						          tmplIds: [tmplIds],
						          success (res) { 
						            console.log('订阅消息 成功 ');
						            console.log(res);
						          },
						          fail (er){
						            console.log("订阅消息 失败 ");
						            console.log(er);
						          }
						        })     
						              
						      }
						    }
						  })
				        }      
				      },
				      fail: function(error){
				        console.log(error);
				      },
				    })
			}
		},
		mounted() {
			//this.getSetting()
		},
		onLaunch: function() {
			wx.hideTabBar()
			let userInfo = uni.getStorageSync('userInfo');
			if(userInfo.name){
				//更新学生登陆状态
				this.login(userInfo);
				//更新Socket连接
				//this.connectSocket(userInfo.id)
			}else{
				uni.navigateTo({
					url: '/pages/login/login'
				})
			} 
		},
		onShow: function() { 
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
		
	} 
</script>

<style lang="scss">
	uni-modal {
	  z-index: 999999 !important;
	}
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/pagesB/uview-ui/index.scss";
	//@import "/uni_modules/uview-ui/index.scss";
	@font-face {
		font-family: yticon;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_1078604_w4kpxh0rafi.ttf') format('truetype');
	}
	/*每个页面公共css */
	
//全局头部 	
.navbar{
		position: fixed;
		left: 0;
		top: var(--window-top);
		//display: flex;
		width: 100%;
		//height: 80upx;
		background:white ;
		box-shadow: 0 2upx 10upx rgba(0,0,0,.06);
		z-index: 10;
}	
//uniapp 表单label 	
	
	/* 设置全局背景色 */
//全局控制状态拦高度	
.status_bar {  
    height: var(--status-bar-height);  
    width: 100%;  
    background-color: #fff;  
}  
.top_view {  
    height: var(--status-bar-height);  
    width: 100%;  
    position: fixed;  
    background-color: #fff;  
    top: 0;  
    z-index: 999;  
} 	
page {
    background-color: #f3f3f3;
	
}
/*未登录 空白页 */
.empty{
	position:fixed;
	left: 0;
	top:0;
	width: 100%;
	height: 100vh;
	padding-bottom:100upx;
	display:flex;
	justify-content: center;
	flex-direction: column;
	align-items:center;
	background: #fff;
	image{
		width: 240upx;
		height: 160upx;
		margin-bottom:30upx;
	}
	.empty-tips{
		display:flex;
		font-size: $font-sm+2upx;
		color: #C0C4CC;
		.navigator{
			color: #fa436a;
			margin-left: 16upx;
		}
	}
}


.content{
	
	border-radius: 15rpx;
}
.uform{
	background-color: white;
	padding:20rpx 30rpx;
}

	.yticon {
		font-family: "yticon" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
/*边框*/
	.b-b:after,
	.b-t:after {
		position: absolute;
		z-index: 3;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
		border-bottom: 1px solid $border-color-base;
	}

	.b-b:after {
		bottom: 0;
	}

	.b-t:after {
		top: 0;
	}
/* 图片载入替代方案 */
.image-wrapper {
	font-size: 0;
	background: #f3f3f3;
	border-radius: 4px;

	image {
		width: 100%;
		height: 100%;
		transition: .6s;
		opacity: 0;

		&.loaded {
			opacity: 1;
		}
	}
}
//设置	checkbox背景色
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
	background-color: $uni-color-title;
}
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before{
	color: #FFFFFF;
} 
uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
    border-color: $uni-color-title;
}
.icon-xuanzhong2:before {
		content: "\e62f";
	}
.icon-fork:before {
		content: "\e61b";
	}
.icon-weixinzhifu:before {
	content: "\e61a";
}
.icon-alipay:before {
	content: "\e636";
}
.icon-erjiye-yucunkuan:before {
		content: "\e623";
	}
/* 按钮主题色	 */		
.Button-Theme-Color{
	background:linear-gradient(90deg, #fedf4d, #ffd014);
	color: black;
}
</style>
